<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回指定类的父类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.class-implements.html">« class_implements</a></li>
      <li style="float: right;"><a href="function.class-uses.html">class_uses »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.spl.html">SPL 函数</a></li>
    <li>返回指定类的父类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.class-parents" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">class_parents</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">class_parents</span> &mdash; <span class="dc-title">
   返回指定类的父类
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.class-parents-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>class_parents</strong></span>(<span class="methodparam"><span class="type"><span class="type">object</span>|<span class="type">string</span></span> <code class="parameter">$object_or_class</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$autoload</code><span class="initializer"> = <strong><code>true</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   本函数返回包含了指定 <code class="parameter">object_or_class</code> 父类名的数组。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.class-parents-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">object_or_class</code></dt>

     <dd>

      <p class="para">
       对象（类实例）或字符串（类名称）。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">autoload</code></dt>

     <dd>

      <p class="para">
       是否默认调用 <a href="language.oop5.autoload.html" class="link">__autoload</a>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.class-parents-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时为数组，当指定类不存在则为 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.class-parents-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3661">
    <p><strong>示例 #1 <span class="function"><strong>class_parents()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{&nbsp;}<br />class&nbsp;</span><span style="color: #0000BB">bar&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">bar</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;可以指定参数为字符串<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">spl_autoload_register</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;使用自动加载去加载“not_loaded”类<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(</span><span style="color: #DD0000">'not_loaded'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [foo] =&gt; foo
)
Array
(
    [foo] =&gt; foo
)
Array
(
    [parent_of_not_loaded] =&gt; parent_of_not_loaded
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.class-parents-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.class-implements.html" class="function" rel="rdfs-seeAlso">class_implements()</a> - 返回指定的类或接口实现的所有接口</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>